<template>
  <div class="nav-bar" :class="{'isFixed': isFixed}">
    <div class="container">
      <div class="pro-title">{{title}}</div>
      <div class="pro-param">
        <a class="param-link" href="javascript:;">概述</a>
        <span class="vertical-line">|</span>
        <a class="param-link" href="javascript:;">参数</a>
        <span class="vertical-line">|</span>
        <a class="param-link" href="javascript:;">用户评价</a>
        <slot name="buy"></slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'nav-bar',
  props: {
    title: String
  },
  data() {
    return {
      isFixed: false
    };
  },
  mounted() {
    window.addEventListener('scroll', this.initHeight);
  },
  methods: {
    initHeight() {
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
      this.isFixed = scrollTop > 151 ? true : false;
    }
  },
  destroyed() {
    window.removeEventListener('scroll', this.initHeight, false);
  }
}
</script>

<style lang="scss" scoped>
@import "../assets/scss/base.scss";
@import "../assets/scss/config.scss";
@import "../assets/scss/mixin.scss";
.nav-bar {
  height: 70px;
  line-height: 70px;
  border-top: 1px solid $colorH;
  background-color: $colorG;
  z-index: 30;
  &.isFixed {
    position: fixed;
    top: 0;
    width: 100%;
    box-shadow: 0 5px 5px $colorE;
  }
  .container {
    @include flex();
    .pro-title {
      color: $colorB;
      font-size: $fontH;
      font-weight: bold;
    }
    .pro-param {
      font-size: $fontJ;
      .param-link {
        color: $colorC;
      }
      .vertical-line {
        padding: 0 10px;
        color: $colorD;
      }
    }
  }
}
</style>